package com.cxyzy.demo.ui.activity

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import com.cxyzy.demo.R
import com.cxyzy.demo.ext.obtainViewModel
import com.cxyzy.demo.ui.adapter.UserAdapter
import com.cxyzy.demo.viewmodels.UserViewModel
import kotlinx.android.synthetic.main.activity_user.*

class UserActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_user)
        val viewModel =  obtainViewModel(UserViewModel::class.java)
        val adapter = UserAdapter()
        adapter.setOnItemClick { user ->
            viewModel.delUser(user.id)
        }
        userRv.adapter = adapter
        viewModel.userList.observe(this, Observer { adapter.submitList(it) })
    }

}
